package com.qd.dict.panda;

import com.cdqidi.constant.ConstantDto;
import com.cdqidi.dict.annotation.FieldBind;
import com.cdqidi.dict.config.IFieldProcess;
import com.qd.common.dict.DictConstant;
import com.qd.system.util.FileConfirmUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 文件路径转换
 *
 * @author sjk
 */
@Component
@RequiredArgsConstructor
public class FileProcessImpl implements IFieldProcess {

    @Override
    public String processName() {
        return DictConstant.FILE_PATH_TRANS;
    }

    @Override
    public Object convertValue(FieldBind fieldBind, Object fieldValue) {
        if (null == fieldValue) {
            return "";
        }
        String path = fieldValue.toString();
        if (path.startsWith(ConstantDto.HTTP)) {
            return path;
        }
        return FileConfirmUtil.getImageFile(path);
    }
}